import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import createSvgIcon from "./vite/plugins/svg-icon";

import electron from 'vite-plugin-electron'
import {resolve} from 'path';

// https://vite.dev/config/
export default defineConfig({
    plugins: [
        vue(),
        createSvgIcon(),
        //electron({}) //以桌面方式启动
    ],
    resolve: {
        alias: {
            // 配置别名
            "@": resolve(__dirname, "./src")
        }
    },
    server: {
        // port: 3000,
        proxy: {
            '/api': {
                target: 'http://localhost:8080',
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/api/, "")
            },
        },
    },
    css: {
        preprocessorOptions: {
            scss: {
                api: `modern-compiler`
            }
        },
        postcss: {
            plugins: [
                {
                    postcssPlugin: 'internal:charset-removal',
                    AtRule: {
                        charset: (atRule) => {
                            if (atRule.name === 'charset') {
                                atRule.remove()
                            }
                        }
                    }
                }
            ]
        }
    }
})

